<?php
    
    include 'database.php';
    
    
    function Save($tempId, $content, $addrs, $title, $countPic){
        $db = new Database();
        
        $sql = "select id from article where tempId=?";
        $rst = $db->SelectEx($sql, array($tempId));
        
        
        if (count($rst)==0) {
            list($ip, $city, $addr, $addrDetail) = $addrs;
            
            $sql = "insert into article (content, createTime, tempId, ip, city, addr, addrDetail, title, countPicture) ".
                "values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $param = array($content, date("Y-m-d H:i:s"), $tempId, $ip, $city, $addr, $addrDetail, $title, $countPic);
            $artId = $db->Run($sql, $param);
            
        }else{
            $sql = "update article set content=? where tempId=?";
            $rs = $db->Run($sql, array($content, $tempId));
            $artId = $rst[0]['id'];
            cout($artId);
        }
        $data = array("id"=>$artId);
        return $data;
    }
    
    
    function Setting($tempId, $params){
        $db = new Database();
        $deadTime = $params['time'];
        if($params['time']=="-1"){
            $deadTime = null;
        }else{
            $tm = time() + (float)($params['time']) * 86400;
            $deadTime = date("Y-m-d H:i:s", $tm);
        }
        
        
        $sql = "update article set title=?, code=?, category=?, timeLength=?, deadTime=?, passwd=?  where tempId=?";
        $rst = $db->Run($sql, array($params['title'], $params['code'], $params['category'], $params['time'], 
            $deadTime, $params['passwd'], $tempId));
        
//         echo $rst;
        
        
    }



?>